package app.fugema.shop.main.evaluate.adapter;

import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseViewHolder;

import android.view.View;

import app.fugema.shop.R;
import app.fugema.shop.databinding.ItemProductQuestionBinding;
import app.fugema.shop.main.evaluate.model.ProductQuestionBean;
import app.fugema.shop.main.evaluate.model.UserAnswerBean;
import app.fugema.shop.main.evaluate.view.QuestionDetailActivity;

public class GoodsQuestionItemMultiType extends BaseItemMultiType<ProductQuestionBean, ItemProductQuestionBinding>
{
    @Override
    public int getLayoutId()
    {
        return R.layout.item_product_question;
    }

    @Override
    public void onBindViewHolder(ItemProductQuestionBinding binding, int position, BaseViewHolder viewHolder, ProductQuestionBean bean)
    {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        if( bean.getAnswerNumber() > 0 )
        {
            UserAnswerBean answerBean = bean.getAnswerInfo();
            binding.tvProductAnswerUser.setText( answerBean.getNick() + "：");
            binding.tvProductAnswer.setText( answerBean.getAcontent() );
            binding.tvProductAnswerUser.setVisibility(View.VISIBLE);
            binding.tvProductAnswer.setVisibility(View.VISIBLE);
        }
        else
        {
            binding.tvProductAnswerUser.setVisibility(View.INVISIBLE);
            binding.tvProductAnswer.setVisibility(View.INVISIBLE);
        }
        /*
        if (viewHolder.getAdapter() != null)
        {
            int pos = getLastGroupPosition(viewHolder.getAdapter(), position);
            if (pos != -1)
            {
                if (binding.clItemView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.clItemView.getLayoutParams();
                    int spc = position - pos;
                    if (spc % 3 == 0) {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_16);
                    } else {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_19);
                    }
                    binding.clItemView.setLayoutParams(marginLayoutParams);
                }
            }
        }
        */
    }


    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, ProductQuestionBean bean)
    {
        super.onItemClick(view, adapter, onclickType, position, bean);
        QuestionDetailActivity.start(view.getContext(), bean.getId());
    }

    private int getLastGroupPosition(BaseRVAdapter adapter, int position) {
        int pos = -1;
        for (int i = position - 1; i >= 0; i--) {
            if (adapter.getItemViewType(i) == TYPE_GROUP) {
                pos = i;
                break;
            }
        }
        return pos;
    }


}
